//reading Clob type

import java.io.FileWriter;
import java.io.Reader;
import java.sql.*;
class JdbcDemo26 {

	public static void main(String[] args) throws Exception {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection cn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
		PreparedStatement ps = cn.prepareStatement("select * from textfile where name = ?");
		ps.setString(1, "naresh");
		ResultSet rs = ps.executeQuery();
		rs.next();
		String name = rs.getString(1);
		Reader r = rs.getCharacterStream(2);
		int n;
		FileWriter fw = new FileWriter("p.txt");
		while((n=r.read())!=-1);
		fw.write(n);
		fw.close();
		
		
		
		
		
		
		
		cn.close();
		ps.close();
		// TODO Auto-generated method stub

	}

}
